package com.wpd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.common.bo.PageBean;
import com.common.bo.ResultMsg;
import com.common.util.StringUtil;
import com.wpd.bo.WpdOrder;
import com.wpd.bo.WpdUser;
import com.wpd.service.IWpdOrderService;

/**
 *
 *  @author : 自动生成
 *  @date   : 2017年07月14日 10:18:16
 *  @desc   : WpdOrder转发控制层
 */

@Controller
@RequestMapping("/wpdOrder")   
public class WpdOrderController {
	 @Autowired
	 private IWpdOrderService wpdOrderService;
	 
	 /**
	 * 初始化界面
	 * @return
	 */
	@RequestMapping(value = "/wpdOrderInit")
	public ModelAndView wpdOrderInit() {
		ModelAndView mv = new ModelAndView("wpdOrder");
		return mv;
	}
	 
	 /**
	 * 保存WpdOrder
	 * 需要参数： wpdOrder WpdOrder对象
	 */
	@RequestMapping(value="/saveWpdOrder")
	@ResponseBody 
	public ResultMsg saveWpdOrder(HttpSession session, @ModelAttribute WpdOrder wpdOrder){
		WpdUser user = (WpdUser)session.getAttribute("user_info");
		if(StringUtil.isEmpty(wpdOrder.getGuid())){
			wpdOrderService.insert(wpdOrder, user);
		}else{
			wpdOrderService.update(wpdOrder, user);
		}
		return new ResultMsg("0", "成功");
	}
	
	/**
	 * 根据WpdOrder传入属性 删除WpdOrder对象
	 * 需要参数  wpdOrder：WpdOrder对象
	 */
	@RequestMapping(value="/deleteWpdOrder")  
	@ResponseBody 
	public ResultMsg deleteWpdOrder(@ModelAttribute WpdOrder wpdOrder){
		wpdOrderService.delete(wpdOrder);
		return new ResultMsg("0", "成功");
	}
	 
	 /**
	  * 获取WpdOrder分页列表
	  */
	 @RequestMapping(value="/queryWpdOrderPageList", produces = {"application/json;charset=UTF-8"})
	 @ResponseBody
	 public ResultMsg queryWpdOrderPageList(
			WpdOrder wpdOrder,HttpServletRequest request,
			@RequestParam(value="pageSize",required=true) Integer pageSize,
			@RequestParam(value="pageIndex",required=true) Integer pageIndex){
		Integer count = wpdOrderService.getTotalCount(wpdOrder);
		PageBean pageBean = new PageBean(pageSize, pageIndex);
		List<WpdOrder> list = wpdOrderService.queryPageList(wpdOrder, pageBean);
		Map<String, Object> extraMap = new HashMap<String, Object>();
		extraMap.put("page", pageIndex);
		extraMap.put("pagesize", pageSize);
		extraMap.put("total", count);
		ResultMsg result = new ResultMsg("0", "成功"); 
		result.setData(list);
		result.setExtra(extraMap);
		return result;
	}

	/**
	 * 得到WpdOrder对象
	 * 需要参数：  wpdOrder：WpdOrder对象
	 */
	@RequestMapping(value="/getWpdOrder")  
	@ResponseBody 
	public ResultMsg getWpdOrder(@ModelAttribute WpdOrder wpdOrder){
		ResultMsg result = new ResultMsg("0", "成功"); 
		result.setData(wpdOrderService.getBean(wpdOrder));
		return result;
	}
}
